package com.lijianlove.keeplearning.dr.support.storage;

import com.lijianlove.keeplearning.dr.utils.TimedConcurrentHashMap;

/**
 * @author lijian
 * @date 2019/4/30 下午5:49
 */
public class MemoryStorageStrtegy implements StorageStrategy {

    /**
     * @param key
     * @param expire
     * @return
     */
    @Override
    public boolean putNX(String key, long expire) {
        if (TimedConcurrentHashMap.getInstance().get(key) != null && TimedConcurrentHashMap.getInstance().get(key) > 0) {
            return false;
        }
        TimedConcurrentHashMap.getInstance().put(key, expire);
        return true;
    }
}
